import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-05-08
 * Time: 8:57
 */
public class Main {
    public static int[] findSaddlePoint(int[][] mList){

    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入矩阵的行数和列数：");
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int[][]arr1=new int [a][b];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                arr1[i][j]=scanner.nextInt();
            }
        }
    }
    public static int[][] sortAllRow(int[][] originM){
        int[][]arr2=new int [originM.length][originM[0].length];
        for (int i = 0; i < originM.length; i++) {
            for (int j = 0; j < originM[0].length; j++) {
               arr2[i][j]=originM[i][j];
            }
        }
        for (int i = 0; i < originM.length; i++) {
            Arrays.sort(arr2[i]);
        }return arr2;
    }

    public static void main14(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入矩阵的行数和列数：");
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int[][]arr1=new int [a][b];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                arr1[i][j]=scanner.nextInt();
            }
        }
        for (int i = 0; i < b; i++) {
            System.out.println(Arrays.toString(sortAllRow(arr1)[i]));
        }

    }
    public static boolean isEqual(int[] list1, int[] list2){
        for (int i = 0; i < list1.length; i++) {
            if(list1[i]!=list2[i]){
                return false;
            }
        }return true;
    }
    public static void main13(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入矩阵的行数和列数：");
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        System.out.printf("请输入矩阵1的%d个数\n",a*b);
        int[]arr1=new int[a*b];
        int[]arr2=new int[a*b];
        for (int i = 0; i < a * b; i++) {
            arr1[i]=scanner.nextInt();
        }
        System.out.printf("请输入矩阵2的%d个数\n",a*b);
        for (int i = 0; i < a * b; i++) {
            arr2[i]=scanner.nextInt();
        }
        if(isEqual(arr1,arr2)){
            System.out.println("两个矩阵是相等的");
        }else{
            System.out.println("两个矩阵是不相等的");
        }

    }
    public static int sumMainDiagonal(int[][] mList){
        int sum=0;
        for (int i = 0; i < 5; i++) {
            sum+=mList[i][i];
        }
        return sum;
    }
    public static void main11(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int[][]arr=new int[5][5];
        System.out.println("请按行输入一个5*5矩阵：");
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                 arr[i][j]=scanner.nextInt();
            }
        }
        System.out.println("主对角线的和是："+sumMainDiagonal(arr));
    }
    public static void reverse(int[] list){
        int left=0;
        int right=list.length-1;
        while(left<=right){
            int tmp=list[left];
            list[left]=list[right];
            list[right]=tmp;
            left++;
            right--;
        }
    }
    public static void reverse(double[] list){
        int left=0;
        int right=list.length-1;
        while(left<=right){
            double tmp=list[left];
            list[left]=list[right];
            list[right]=tmp;
            left++;
            right--;
        }
    }
    public  static void toStringPrint(double[]arr){
        System.out.printf("[%.2f",arr[0]);
        for (int i = 1; i < 9; i++) {
            System.out.printf(",%.2f",arr[i]);
        }
        System.out.printf(",%.2f]\n",arr[9]);
    }
    public static void main10(String[] args) {
        int[] arr1=new int[10];
        double[] arr2=new double[10];
        Random random=new Random();
        for (int i = 0; i < 10; i++) {
            arr1[i]=random.nextInt(101);
            arr2[i]=random.nextDouble(101);
        }

        System.out.println("逆置前，整数数组：");
        System.out.println(Arrays.toString(arr1));
        System.out.println("逆置前，double数组：");
        toStringPrint(arr2);
        reverse(arr1);
        reverse(arr2);
        System.out.println("逆置后，整数数组：");
        System.out.println(Arrays.toString(arr1));
        System.out.println("逆置后，double数组：");
        toStringPrint(arr2);

    }
    public static void main8(String[] args) {
        int arr[]={2,6,4,1};
        int pcur=0;
        int cur=0;
        int n=0;
        while(cur<arr.length){
            if(arr[cur]%2!=0){
                n++;
                if(n==1){
                    pcur=cur;
                }
            }else{
                n=0;
            }
            cur++;
            if(n==3){
                System.out.print("true"+"\n"+"[");
                for (int i = 0; i < 2; i++) {
                    System.out.print(arr[pcur+i]+",");
                }
                System.out.print(arr[pcur+2]+"]");

            }if(cur==arr.length-1&&n!=3){
                System.out.println(false);
            }
        }

    }
    public static void main7(String[] args) {
        int[]arr={2,2,1,1,1,2,2};
        Arrays.sort(arr);
        for (int i = 0; i < arr.length/2+1; i++) {
            if(arr[i]==arr[i+ (arr.length/2)]){
                System.out.println(arr[i]);
            }
        }
    }
    public static int findSingle(int[]arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if(arr[i]==arr[j]&&i!=j) break;
                if(j==arr.length-1) return arr[i];
            }
        }return -1;
    }

    public static void main6(String[] args) {
        int[]arr={4,1,2,1,2};
        System.out.println(findSingle(arr));
    }
    public static String findSum(int[] arr,int key){
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]+arr[j]==key){
                    String ret="["+i+","+j+"]";
                    return ret;
                }
            }
        }return "找不到";
    }

    public static void main5(String[] args) {
        int[]arr={2,7,11,15};
        System.out.println(findSum(arr,9));
    }
    public static void bubbleSort(int[]arr){
        for (int i = 0; i < arr.length; i++) {
            int tmp=0;
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    tmp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=tmp;
                }
            }if(tmp==0){
                break;
            }
        }
    }
    public static void main4(String[] args) {
        //冒泡排序
        int[]arr={1,8,4,5,6,3,2,7,2};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static int binarySearch(int[]arr,int key){
        int left=0;
        int right=arr.length-1;
        while(right>=left){
            int mid=(left+right)/2;
            if(arr[mid]==key){
                return mid;
            } else if (arr[mid]>key) {
                right=mid-1;
            }else{
                left=mid+1;
            }
        }return -1;
    }
    public static void main3(String[] args) {
        //二分查找
        int[]arr={1,2,3,4,5,6,7,8};
        System.out.println(binarySearch(arr,8));;
    }
    public static void adjust(int[]arr){
        int dest=arr.length-1;
        for (int i = 0; i < arr.length; i++) {
            boolean fag=true;
            int cur=0;
            int tmp=0;
            while(dest>cur){
                if(arr[cur]%2==0){
                    tmp=arr[cur];
                    arr[cur]=arr[dest];
                    arr[dest]=tmp;
                    dest--;
                    fag=false;
                } cur++;

            }if(fag){
                break;
            }
        }
    }
    public static void main2(String[] args) {
        int[]arr={1,2,3,4,5,6};
        adjust(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static int[] transform(int[]arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i]*=2;
        }
        return arr;
    }
    public static void main1(String[] args) {
        int[]arr={1,2,3};
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(transform(arr)));

    }
}